# encoding: utf-8
# @author: wangxin
# @software: garner
# @file: listViews.py
# @time: 2025/2/13 10:49
import json

from django.core import serializers
from django.db.models import Q
from django.http import HttpResponse, JsonResponse
from django.views import View

from app.models import TSetmeal


class List(View):
    def get (self, request):
        setMeal_list = TSetmeal.objects.filter(Q(is_show=1))

        Set_Meal_Json_List = json.loads(serializers.serialize('json', setMeal_list))
        data_list = []
        for Set_Meal_Json in Set_Meal_Json_List:
            data_josn = Set_Meal_Json["fields"]
            CheckGroup_id = Set_Meal_Json['pk']  # 取检查项id
            data_josn["id"] = CheckGroup_id  # 将检查项id赋值给id字段
            # print(CheckGroup_id)
            data_list.append(data_josn)
        result = {
            "status": "200",
            "message": "获取检查套餐成功",

            "data": data_list

        }
        print(data_list)
        return JsonResponse(result)